package com.sxt.sys.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.sxt.sys.constant.SYSConstant;
import com.sxt.sys.domain.Operator;
import com.sxt.sys.mapper.OperatorMapper;
import com.sxt.sys.service.OperatorService;
import com.sxt.sys.utils.DataView;
import com.sxt.sys.vo.OperatorVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author WanMing
 * @date 2019/1/31 10:11
 */

@Service
public class OperatorServiceImpl implements OperatorService {

    @Autowired
    private OperatorMapper operatorMapper;

    /**
     * 根据操作员的名字查询该对象
     *
     * @param operatorName
     * @return
     */
    @Override
    public Operator queryOperatorByOperatorName(String operatorName) {

        return operatorMapper.queryOperatorByOperatorName(operatorName);
    }

    /**
     * 分页+模糊产查询
     *
     * @param operatorVo
     * @return
     */
    @Override
    public DataView queryAllOperator(OperatorVo operatorVo) {
        Page page = PageHelper.startPage(operatorVo.getPage(),operatorVo.getLimit());
        List<Operator> operators = operatorMapper.queryAllOperator(operatorVo);
        return new DataView(SYSConstant.STATUS_CODE,SYSConstant.STATUS_MSG,page.getTotal(),operators);
    }

    /**
     * 添加操作员
     *
     * @param operatorVo
     */
    @Override
    public void addOperator(OperatorVo operatorVo) {
        operatorMapper.insertSelective(operatorVo);
    }
}
